####################################
#Diff-in-diff with matching and dual-distance cutoffs - PA figure, dd with dd 
#Traffic and Political Attitudes
#Connor Jerzak & Brian Libgober
#76/276/70, 476: HAS ez-passes  
#79, 80, 81, : NO EZPass 
####################################


########################
#Initial setup 
########################
#set wd
setwd("/Users/cjerzak/Documents/Publications/Traffic/Internals/")

#external libraries 
library(ggplot2)

#load in data 
#NJ_data <- read.csv("NJ_precinct_master.csv", header=T)
PA_data <- read.csv("PA_precinct_master.csv", header=T)


#load in the dd_with_dd function 
source("dd_with_dd_function.R")

##############################
#set variable values
##############################


#set general specifications for later modifications
my_data <- PA_data 

#outcomes 
outcome_time1_name <- "USPP2000"
outcome_time2_name <- "USPP2004"  #US president (dem) percent 2000, 2004

#identify matching variables 
matching_variables <- c("cepctwhite", "cepctblack", "cepctwomen", "cnipoverty", "cnpopurban") #income, commute length, number of cars, etc. 

#treated basis (something having to do with E-ZPasses)
treatment_basis_name <- "EZDist_PA_NEAR_DIST" 

#control basis (something having to do with non-E-ZPass highway)
control_basis_names <- c("HighwayDist_PA79_NEAR_DIST", 
                         "HighwayDist_PA80_NEAR_DIST", 
                         "HighwayDist_PA81_NEAR_DIST")

#define cutoffs 
treatment_basis_treated_max <- 250
control_basis_control_max <- 250
treatment_basis_control_min <- 20000#summary(my_data[,which(colnames(my_data)==treatment_basis_name)])[[3]] #(mean quartile)
control_basis_treated_min <- 20000 #summary(my_data[,which(colnames(my_data)==control_basis_name)])[[3]] #(mean quartile)


##############################
#single trial 
##############################
initial_results <- dd_with_dd(my_data=my_data,
                              treatment_basis_name=treatment_basis_name, 
                              control_basis_names=control_basis_names, 
                              outcome_time1_name=outcome_time1_name, 
                              outcome_time2_name=outcome_time2_name,
                              matching_variables=matching_variables,
                              treatment_basis_treated_max=treatment_basis_treated_max, 
                              treatment_basis_control_min=treatment_basis_control_min, 
                              control_basis_control_max=control_basis_control_max,
                              control_basis_treated_min=control_basis_treated_min,
                              boostrap_SDs=F, 
                              bootstrap_numb=10, 
                              conf_level=0.95, 
                              start_browser=F)
initial_results
